#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int a[10];
bool ss(int n)//素数
{
    for (int i = 2; i <= sqrt(n); ++i) 
	{
        if(n%i==0)return 0;
    }
    return 1;
}
bool hw(int n)//回文
{
    int i=0;
    while (n!=0){
        a[i++]=n%10;
        n/=10;
    }
    for (int j = 0; j < i; ++j) 
	{
        if(a[j]!=a[i-j-1])return 0;
    }
    return 1;
}
int main(){
    int m,num=0;
    cin>>m;
    for (int i = 11; i <= m; ++i) //判断
	{
        if(ss(i)&&hw(i))
		{
            num++;
        }
    }
    cout<<num;
}
